package com.example.demo;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service
public class SpringBoot_Service {
	@Autowired
	private SpringBoot_Dao springDao;
	public void testException(String param) throws Exception{
		if(param.equals("1")){
			System.out.println("没有异常");
		}else{
			System.out.println("存在异常");
		}
	}
	public void testSql(JdbcTemplate jdbcParam) throws Exception{
		try {
			List<Map<String,Object>> list=jdbcParam.queryForList("select top 10 * from v_vehicleinfo");
			for(int i=0;i<list.size();i++){
				System.out.println(list.get(i).get("vehicleid"));
			}
		} catch (Exception e) {
			// TODO: handle exception
			throw new Exception(e);
		}
		
		
	}
	public void tException(){
		String a=null;
		if(a.equals("123")){
			System.out.println("你好");
		}
	}
	public void tException1() throws Exception{
		throw new SQLException("tException1数据库连接失败");
	}
	public void testSqlConnect(JdbcTemplate jdbcParam){
		springDao.testSqlConnect(jdbcParam);
		springDao.testEx(null);
	}
}
